package com.ruyuan.scholartrade.controller;

import com.scholar.shop.common.CommonRes;
import com.scholar.shop.trad.pintuan.api.PintuanAPI;
import com.scholar.shop.trad.pintuan.domain.PintuanVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * PintuanClientDefaultImpl
 *
 * @author Chopper
 * @version v1.0
 * @since v7.0
 * 2019-02-18 上午11:44
 */
@CrossOrigin
@RestController
@RequestMapping("/trade/pintuan/open/api")
public class PintuanAPIController  {
    @Autowired
    private PintuanAPI pintuanAPI;

    /**
     * 获取拼团
     *
     * @param id 拼团主键
     * @return Pintuan  拼团
     */
    
    @GetMapping("/{id}" )
    public CommonRes<PintuanVO> getModel(@PathVariable Integer id) {
        return pintuanAPI.getModel(id);
    }

    /**
     * 停止一个活动
     *
     * @param promotionId
     * @return
     */
    
    @PostMapping("/closePromotion/{promotionId}")
    public CommonRes<Boolean> closePromotion(@PathVariable Integer promotionId) {
        pintuanAPI.closePromotion(promotionId);
        return CommonRes.success(true) ;
    }

    /**
     * 开始一个活动
     *
     * @param promotionId
     * @return
     */
    
    @PostMapping("/openPromotion/{promotionId}")
    public CommonRes<Boolean> openPromotion(@PathVariable Integer promotionId) {
        pintuanAPI.openPromotion(promotionId);
        return CommonRes.success(true) ;
    }

    
    @GetMapping("/getListByStatus/{status}")
    public CommonRes<List<PintuanVO>> get(@PathVariable String status) {
        return this.pintuanAPI.get(status) ;
    }
}
